class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        // 这道题几乎和《283.移动零》有异曲同工之处(双指针法)
        int prev = -1;
        for(int cur = 0; cur < nums.size(); cur++)
            if(nums[cur] != val)
                swap(nums[++prev], nums[cur]);
        return ++prev;
    }
};